home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
datecls.exe
/
DATEDEMO.CPP
< prev
next >
Wrap
Text File
|
1992-06-28
|
6KB
|
150 lines
#include "datecls4.h"
////////////////////////////////////////////////////////////
// main for testing purposes only...
////////////////////////////////////////////////////////////
void main()
{
cout << " Date Class v4.0 Demo \n\n";
// Various versions of the constructors
// and various output
Date x(10,20,1962);
cout << x.formatDate(FULL) << "\n";
// constuctor with a string, just printing the day of the week
Date y="8/8/1988";
cout << y.formatDate(DAY) << "\n";
// constructor with a julian
Date z( 2450000L );
cout << z.formatDate(FULL) << '\n';
// using date addition and subtraction
Date a = x + 10;
cout << a.formatDate(FULL) << '\n';
a = a - 25;
cout << a.formatDate(EUROPEAN) << '\n';
//using subtraction of two date objects
Date a1 = "7/13/1991";
Date a2 = a1 + 14;
cout << (a1-a2) << "\n";
cout << (a2+=10) << "\n";
a1++;
cout << "Tommorrow= " << a1.formatDate(FULL) << "\n";
cout << "a1 (7-14-91) < 8-01-91 ? ==> " << ((a1 < "08/01/1991") ? "TRUE" : "FALSE") << "\n";
cout << "a1 (7-14-91) > 8-01-91 ? ==> " << ((a1 > "08/01/1991") ? "TRUE" : "FALSE") << "\n";
cout << "a1 (7-14-91)== 7-14-91 ? ==> " << ((a1==(Date)"07/14/1991") ? "TRUE" : "FALSE") << "\n";
Date a3 = a1;
cout << "a1 (7-14-91)== a3 (7-14-91) ? ==> " << ((a1==a3) ? "TRUE" : "FALSE") << "\n";
Date a4 = a1;
cout << "a1 (7-14-91)== a4 (7-15-91) ? ==> " << ((a1==++a4) ? "TRUE" : "FALSE") << "\n";
Date a5 = "today";
cout << "Today is: " << a5 << "\n";
a4 = "Today";
cout << "Today (a4) is: " << a4 << "\n";
cout << "Today + 4 is: " << (a4+=4) << "\n";
a4 = "TODAY";
cout << "Today - 4 is: " << (a4-=4) << "\n";
cout << "=========== Leap Year Test ===========\n";
a1 = "1/15/1992";
cout << a1.formatDate(FULL) << "\t" << ((a1.isLeapYear()) ? "Leap" : "non-Leap");
cout << "\t" << "day of year: " << a1.DOY() << "\n";
a1 = "2/16/1993";
cout << a1.formatDate(FULL) << "\t" << ((a1.isLeapYear()) ? "Leap" : "non-Leap");
cout << "\t" << "day of year: " << a1.DOY() << "\n";
_dosdate_t b0 = {15,02,1991,1};
Date b1 = b0;
cout << "=========== eom test ==============\n";
cout << "b1.eom() (s/b 2/28/91) ==> " << b1.eom() << "\n";
cout << "================== getDate test =====================\n";
_dosdate_t ds = a1.getDate();
cout << "a1.getDate() (s/b 2/16/1993) ==> " << ds << "\n";
cout << "================== string assignment test ====================\n";
char *date_string=a1;
cout << "a1 as a string (s/b 2/16/1993) ==> " << date_string << "\n";
cout << "================== setFormat test ============================\n";
Date::setFormat(FULL);
cout << "a1 (s/b FULL format) ==> " << a1 << "\n";
Date::setFormat(EUROPEAN);
cout << "a1 (s/b EUROPEAN format) ==> " << a1 << "\n";
cout << "================== setOption test ============================\n";
cout << "Date abbreviation ON\n";
Date::setOption(DATE_ABBR);
Date::setFormat(MONTH);
cout << "a1 (s/b MONTH format) ==> " << a1 << "\n";
Date::setFormat(DAY);
cout << "a1 (s/b DAY format) ==> " << a1 << "\n";
Date::setFormat(FULL);
cout << "a1 (s/b FULL format) ==> " << a1 << "\n";
Date::setFormat(EUROPEAN);
cout << "a1 (s/b EUROPEAN format) ==> " << a1 << "\n";
cout << "Century suppression ON\n";
Date::setOption(NO_CENTURY);
Date::setFormat(MDY);
cout << "a1 (s/b MDY format) ==> " << a1 << "\n";
cout << "Century suppression OFF\n";
Date::setOption(NO_CENTURY,OFF);
cout << "a1 (s/b MDY format) ==> " << a1 << "\n";
cout << "Century suppression ON\n";
Date::setOption(NO_CENTURY);
cout << "a1 (s/b MDY format) ==> " << a1 << "\n";
Date::setFormat(FULL);
cout << "a1 (s/b FULL format) ==> " << a1 << "\n";
Date::setOption(DATE_ABBR,OFF);
cout << "\n=============== Version 4.0 Enhancement Test =================\n";
Date v4("11/26/1966");
cout << "\n---------- Set Stuff -----------\n";
cout << "First, 'Set' to today..." << "\n";
cout << "Before 'Set' => " << v4 << "\n";
cout << "After 'Set' => " << v4.Set() << "\n\n";
cout << "Set to 11/26/66 => " << v4.Set(11,26,1966) << "\n";
cout << "Current Julian => " << v4.julDate() << "\n";
cout << "Set to Julian 2450000L => " << v4.Set(2450000L) << "\n";
cout << "See! => " << v4.julDate() << "\n";
cout << "---------- Add Stuff -----------\n";
cout << "Start => " << v4 << "\n";
cout << "Add 4 Weeks => " << v4.AddWeeks(4) << "\n";
cout << "Sub 1 Month => " << v4.AddMonths(-1) << "\n";
cout << "Add 2 Years => " << v4.AddYears(2) << "\n";
cout << "---------- Misc Stuff -----------\n";
cout << "The date aboves' day of the month is => " << v4.Day() << "\n";
cout << "There are " << v4.DaysInMonth() << " days in this month.\n";
cout << "The first day of this month lands on " << v4.FirstDOM() << "\n";
cout << "This day happens to be " << v4.CDOW() << "\n";
cout << "the " << v4.NDOW() << " day of the week," << "\n";
cout << "on the " << v4.WOY() << " week of the year," << "\n";
cout << "on the " << v4.WOM() << " week of the month, " << "\n";
cout << "(which is " << v4.CMonth() << ")\n";
cout << "the "<< v4.NMonth() << "nth month in the year.\n";
cout << "The year alone is " << v4.NYear4() << "\n";
cout << "---------- First and Last Stuff -----------\n";
v4.Set();
cout << "The first date of this month is " << v4.BOM() << "\n";
cout << "The last date of this month is " << v4.EOM() << "\n";
cout << "The first date of this year is " << v4.BOY() << "\n";
cout << "The last date of this year is " << v4.EOY() << "\n";
}